package com.hspedu.homework;

import org.junit.Test;

import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/4/17
 * @time 16:02
 */
public class Homework {

    @Test
    public void test1(){
        String content = "韩顺平教育";

        String regStr = "^[\u0391-\uffe5]+$";

        Pattern pattern = Pattern.compile(regStr);
        Matcher matcher = pattern.matcher(content);
        if (matcher.find()){
            System.out.println(matcher.group(0));
        }
    }

    @Test
    public void test2(){
        String content = "123890";
        String regStr = "^[1-9]\\d{4}\\d$";

        Pattern pattern = Pattern.compile(regStr);
        Matcher matcher = pattern.matcher(content);
        while (matcher.find()){
            System.out.println(matcher.group(0));
        }
    }

    @Test
    public void test3(){
        String content = "123";
        String regStr = "^[1-9]\\d{3,8}\\d$";

        Pattern pattern = Pattern.compile(regStr);
        Matcher matcher = pattern.matcher(content);
        while (matcher.find()){
            System.out.println(matcher.group(0));
        }
    }

    @Test
    public void test4(){
        String content = "123";
        String regStr = "^1(?:3|4|5|8)\\d{9}$";
        Pattern pattern = Pattern.compile(regStr);
        Matcher matcher = pattern.matcher(content);
        while (matcher.find()){
            System.out.println(matcher.group(0));
        }
    }

    @Test
    public void test5(){
        String content = "https://apps.youkeda.com/learn/develop?stage=P2";
        String regStr = "^(http(?:://|s://))([\\w-]+\\.)+([\\w-])+(\\/[\\w-?=&.#]*)*$";
        Pattern pattern = Pattern.compile(regStr);
        Matcher matcher = pattern.matcher(content);
        while (matcher.find()){
            System.out.println(matcher.group(0));
        }
    }

    @Test
    public void test6(){
        String content = "hello jack tom11 jack22 yyy xxx";
        String regStr = "(\\d)\\1";
        Pattern pattern = Pattern.compile(regStr);
        Matcher matcher = pattern.matcher(content);
        while (matcher.find()){
            System.out.println(matcher.group(0));
        }
    }

    @Test
    public void test7(){
        String content = "hello333333,12345";
        String regStr = "(\\d)\\1{4}";
        Pattern pattern = Pattern.compile(regStr);
        Matcher matcher = pattern.matcher(content);
        while (matcher.find()){
            System.out.println(matcher.group(0));
        }
    }

    /**
     * 结巴去重
     */
    @Test
    public void test8(){
        String content = "我....我要....学学学学....编程java!";
        Pattern pattern = Pattern.compile("\\.");
        Matcher matcher = pattern.matcher(content);
        String newContent = matcher.replaceAll("");
        System.out.println(newContent);

        //查找重复的汉字
        Pattern pattern1 = Pattern.compile("(.)\\1+");
        Matcher matcher1 = pattern1.matcher(newContent);
        while (matcher1.find()){
            System.out.println(matcher1.group(0));
        }

        //使用反向引用 $1 替换匹配到的内容
        content = matcher1.replaceAll("$1");
        System.out.println(content);
    }

    @Test
    public void test9(){
        String content = "2000年5月，JDK1.3、JDK1.4和J2SE1.3相继发布，几周后其" +
                "获得了Apple公司Mac OS X的工业标准的支持。2001年9月24日，J2EE1.3发" +
                "布。" +
                "2002年2月26日，J2SE1.4发布。自此Java的计算能力有了大幅提升";
        String newContent = content.replaceAll("JDK(?:1.3|1.4)", "JDK");
        System.out.println(newContent);
    }

    @Test
    public void test10(){
        String content = "13988889999";
        boolean matches = content.matches("13(?:8|9)\\d{8}");
        System.out.println(matches);
    }

    @Test
    public void test11(){
        String content = "hello#abc-jack12smith~北京";
        String[] split = content.split("#+|-+|~+|\\d+");
        System.out.println(Arrays.toString(split));
    }

}
